/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sourcery;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import sourceryobjects.sPoint;

/**
 *
 * @author claire
 */
public class GraphicsContext {
    private Graphics2D g;
    private static final int DEFAULT_SIZE = 30;
    public enum NodeType {
        BASEOBJECT,
        OBJECTMETHOD,
        OBJECTPROPERTY

    } ;
    public enum LineStyles { NONE, PURPLE, GREEN };


    private boolean init(Graphics2D g) {
        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        
        rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        this.g = g;
        g.setRenderingHints(rh);
        return true;
    }

    public GraphicsContext(Graphics g) {
        this.init((Graphics2D) g);
    }
    public GraphicsContext(Graphics2D g) {
        this.init(g);
    }
    public Graphics2D getGraphics() {
        return g;
    }
    public void DrawNode(double x, double y, double size, NodeType k) {
        switch(k) {
            case BASEOBJECT:
                Ellipse2D c = new Ellipse2D.Double(x,y,size,size);
                g.setPaint(Color.RED);
                g.fill(c);
                g.setPaint(Color.GRAY);
                g.draw(c);
                break;
            default:
                break;
        }
    }

    public void DrawLine(sPoint a, sPoint b, LineStyles style) {
        Line2D line = new Line2D.Double(a.getX(), a.getY(), b.getX(), b.getY());
        switch(style) {
            case PURPLE:
                g.setPaint(Color.MAGENTA);
                g.draw(line);
                break;
            case GREEN:
                g.setPaint(new GradientPaint(line.getP1(), Color.GREEN, line.getP2(), Color.RED));
                g.draw(line);
                break;
        }
    }
}
